/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn;

import cn.webrx.config.AppConfig;
import cn.webrx.config.DruidConfig;
import cn.webrx.pojo.Book;
import cn.webrx.pojo.Student;
import cn.webrx.pojo.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import javax.annotation.Resource;
import javax.annotation.Resources;

/**
 * <p>Project: spring2022 - SpringDemo
 * <p>Powered by webrx On 2022-03-17 16:00:48
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@SpringJUnitConfig(classes = {AppConfig.class})
public class SpringDemo {


    @Autowired(required = false)
    Book book;

    @Test
    public void t5(){
        System.out.println(book);
    }


    @Value("${db.username}")
    String username;

    @Autowired
    ApplicationContext ctx;

    //@Autowired
    //User wu; //user wu

    @Resource(name = "user")
    User user;

    @Autowired(required = false)
    QueryRunner run;

    @Autowired(required = false)
    Student zs;

    @Test
    public void t4(){
        System.out.println(zs);
        System.out.println(ctx.getBean("lisi"));
        System.out.println(username);
    }


    @Test
    public void t3(){
        try{
            //List<String>
            System.out.println(run.query("select @@version,@@port,@@basedir,@@datadir",new MapHandler()));
        }catch(Exception e){
            e.printStackTrace();
        }
        System.out.println(user);
    }

    @Test
    public void t2(){
        System.out.println(user);
        System.out.println(user == ctx.getBean("wu"));
        System.out.println(ctx.getBean("wu"));
    }

    @Test
    public void t1(){
        for (String n : ctx.getBeanDefinitionNames()) {
            System.out.println(n);
        }
    }
}
